package com.ipan.weixin.msg.menu;

import com.ipan.weixin.msg.AbstractJsonMsg;

/**
 * 菜单查询消息
 * 
 * @author iPan
 * @version 2013-12-26
 */
public class SearchMenuMsg extends AbstractJsonMsg {

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 6542462594365403404L;

	private MenuBean menu;

	public MenuBean getMenu() {
		return menu;
	}

	public void setMenu(MenuBean menu) {
		this.menu = menu;
	}
	
	public synchronized void check() {
		if (menu == null) {
			menu = new MenuBean();
		}
	}

	public void addButton(ButtonBean but) {
		check();
		menu.addButton(but);
	}

	public void addButton(String type, String name, String key, String url) {
		check();
		menu.addButton(new ButtonBean(type, name, key, url));
	}

//	public static void main(String[] args) throws Exception {
//		URL url = CreateMenuMsg.class.getResource("test.js");
//		BufferedReader reader = null;
//		String line = null;
//		StringBuilder buf = new StringBuilder();
//		try {
//			reader = new BufferedReader(new InputStreamReader(new FileInputStream(url.getFile())));
//			while ((line=reader.readLine()) != null) {
//				buf.append(line);
//			}
//		} catch (Exception e) {
//			e.printStackTrace();
//		} finally {
//			if (reader != null) {
//				reader.close();
//			}
//		}
//		SearchMenuMsg msg = AbstractJsonMsg.fromJson(buf.toString(), SearchMenuMsg.class);
//		System.out.println(msg);
//	}
}
